/**
 * @author rxliuli
 */
const {
    arrayToMap,
} = rx
const validate = (() => {
    return RxFormValidator.validator({
        rxElemValidators: [
            RxElemValidator.limitLen('startIp', '[起始IP地址] 长度最大为 64 位', 64),
            RxElemValidator.limitLen('endIp', '[终止IP地址] 长度最大为 64 位', 64),
            RxElemValidator.limitLen('useCompany', '[使用单位] 长度最大为 64 位', 64),
            RxElemValidator.limitLen('idNumber', '[证件号码] 长度最大为 50 位', 50),
        ],
    })
})()
const app = new BasicTableVue({
    data() {
        return {
            api: baseIpAddressInfoApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'id', title: 'ID'}),
                new TableColumn({prop: 'startIp', title: '起始IP地址'}),
                new TableColumn({prop: 'endIp', title: '终止IP地址'}),
                new TableColumn({prop: 'houseName', title: '机房名称'}),
                new TableColumn({
                    prop: 'useType',
                    title: '使用方式',
                    formatter: fieldFormatter.facade(fieldFormatter.baseIpAddressInfo.useTypeMap)
                }),
                new TableColumn({prop: 'useCompany', title: '使用单位'}),
                new TableColumn({prop: 'idNumber', title: '证件号码'}),
                new TableColumn({
                    prop: 'assignUseTime', title: '分配使用时间', formatter: TableColumn.dateFormat,
                }),
                new TableColumn({prop: 'reportStatus', title: '报备状态', formatter: fieldFormatter.facade(fieldFormatter.baseData.reportStatusMap)}),
                new TableColumn({
                    prop: 'operating',
                    title: '操作',
                    customComponent: 'true',
                }),
            ],
            baseHouseInfoList: [],
            validate,
        }
    },
    methods: {
        createForm() {
            return new BaseIpAddressInfo({
                houseId: forward.getData().id,
                assignUseTimeRange: null,
                useCompanyAction: null,
            })
        },
        update({row}) {
            forward('/basic-data/modify/admin_ip_seg_info_modify', row)
        },
        async init() {
            this.baseHouseInfoList = await baseHouseInfoApi.selectList()
        },
        async downloadTemplate() {
            await baseIpAddressInfoApi.downloadTemplate('IP地址信息管理导入模板.xlsx')
        },
    }
})
